#ifndef __DRV_TM16XX_H
#define __DRV_TM16XX_H

#ifdef __cplusplus
 extern "C" {
#endif 

#include "stdint.h"
#include "drv_tm16xx.h"

#define  TM16XX_STB_H
#define  TM16XX_STB_L
#define  TM16XX_CLK_H
#define  TM16XX_CLK_L
#define  TM16XX_DIO_H
#define  TM16XX_DIO_L
#define  TM16XX_DIO_STATUS
#define  TM16XX_DIO_OUTPUT
#define  TM16XX_DIO_INPUT
#define  TM16XX_DELAY


#define TM16XX_READ_BYTE(byte) \
    do{ \
        TM16XX_STB_L; \
        for(uint8_t i=0;i<8;i++) \
        { \
            TM16XX_CLK_L; \
            byte >>= 1; \
            TM16XX_DELAY; \
            TM16XX_CLK_H; \
            TM16XX_DELAY; \
            if(TM16XX_DIO_STATUS) \
            { \
                byte |= 0x80; \
            } \
        } \
     }while(0);
 
 
#define TM16XX_WRITE_BYTE(byte) \
    do{ \
        TM16XX_STB_L; \
        for(uint8_t i=0;i<8;i++) \
        { \
            TM16XX_CLK_L; \
            if(byte & 0x01) \
            { \
                TM16XX_DIO_H; \
            }else \
            { \
                TM16XX_DIO_L; \
            } \
            TM16XX_DELAY; \
            TM16XX_CLK_H; \
            byte >>= 1; \
            TM16XX_DELAY; \
        } \
    }while(0);
 


 uint8_t tm1668_readbyte(void);

 void tm1668_writebyte(uint8_t byte);

 void tm1668_writecmd(uint8_t cmd);

 void tm1668_readkey(uint8_t *pbuffer, uint8_t len);

 void tm1668_display(uint8_t addr,const uint8_t *pbuffer,uint8_t len);

 void tm1668_display_cleanall(void);

 void tm1668_display_off(void);

 void tm1668_display_on(void);

 int drv_tm1668_init(void);

#ifdef __cplusplus
}
#endif

#endif 

